package IO.Commons_IO;


import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class commTest01 {
    public static void main(String[] args) throws IOException {
        //文件/目录大小
        long len = FileUtils.sizeOf(new File("src/IO/Commons_IO"));
        System.out.println(len);

        //列出子孙集

        //读取文件
        String msg = FileUtils.readFileToString(new File("src/IO/abc.txt"),"UTF-8");
        System.out.println(msg);
        byte[] data = FileUtils.readFileToByteArray(new File("src/IO/abc.txt"));
        System.out.println(data.length);

        //逐行读取
        List<String> msgs =  FileUtils.readLines(new File("src/IO/abc.txt"),"UTF-8");
        for (String string:msgs
             ) {
            System.out.println(string);
        }

        //写出文件
        FileUtils.write(new File("src/IO/abc.txt"),"学习使我快乐","UTF-8");
        FileUtils.writeStringToFile(new File("src/IO/abc.txt"),"学习使我快乐","UTF-8",true);
        FileUtils.writeByteArrayToFile(new File("src/IO/abc.txt"),"学习使我快乐3".getBytes("UTF-8"),true);

        //写出列表
        List<String> datas=new ArrayList<>();
        datas.add("马原");
        datas.add("弼马温");
        FileUtils.writeLines(new File("src/IO/abc.txt"),datas,"...",true);
    }
}
